package com.qf.blog.service.impl;

import com.qf.blog.dto.IndexPostDto;
import com.qf.blog.entity.Post;
import com.qf.blog.service.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminService {

    @Autowired
    private IPostService postService;

    @Autowired
    private LikeService likeService;

    public List<IndexPostDto> postList() {

        // 1.查询所有的帖子(帖子id，帖子作者，状态，是否置顶，发布时间，点赞数量)
        List<IndexPostDto> postDtos = postService.adminPostList();

        // 2、查询帖子的点赞数量
        for (IndexPostDto postDto : postDtos) {
            Post post = postDto.getPost();
            post.setLikeCount(likeService.likeSize(post.getId(), 1));
        }
        return postDtos;
    }
}
